<?php
namespace Home\Controller;
// use Think\Controller;
class KeepController extends CommonController {
    
    public function add_Keep(){
        //取得当前用户id
        $uid = session('user')['id'];
        //取得商品id
        $gid = I('get.id');
        // echo $uid;
        // echo 'sadf';
        //查询数据，判断该用户是否已经收藏该商品
        $map['uid'] = ['eq',$uid];
        $map['gid'] = ['eq',$gid];
        //实例化收藏表keep
        $keep = M('keep');
        $res = $keep->where($map)->select();
        if($res){
            echo '不能重复收藏同一件商品';
        }else{
            //加入收藏表
            $data['uid'] = $uid;
            $data['gid'] = $gid;
            $data['addtime'] = time();
            $res = $keep->add($data);
            if($res){
                echo '收藏成功';
            }else{
                echo '收藏失败';
            }
        }
    }
}